package com.shujia.wyh.day22.homework;

public class Student2 implements Comparable<Student2> {
    //学号，姓名，年龄信息
    private String id;
    private String name;
    private int age;

    public Student2() {
    }

    public Student2(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student2 o) {
        //主要条件：按照年龄正序排序
        int i = this.age - o.age;
        //隐含条件：年龄一样，姓名不一定一样
        int i2 = (i == 0) ? this.name.compareTo(o.name) : i;
        return i2;
    }
}
